<template>
    <div class="default-main2 ba-table-box2" style="margin-top: 15px">
        <el-card style="width:98%;float: left;margin-left: 1%;height:580px;margin-top: 0;">
            
            <div style="width: 600px;margin-left: 50px;" v-loading="load">
                <el-form :model="form" label-width="230" style="max-width: 100%">

                    <el-form-item label="开启首单优惠">
                        <el-switch v-model="form.status"></el-switch>
                    </el-form-item>

                    <el-form-item label="优惠类型">
                        <el-radio-group v-model="form.type">
                            <el-radio :value="1">首单立减金额</el-radio>
                            <el-radio :value="2">首单享受折扣</el-radio>
                        </el-radio-group>

                    </el-form-item>

                    <el-form-item label="立减金额" v-if="form.type==1">
                        <el-input v-model="form.money" type="number"/>
                    </el-form-item>
                    <el-form-item label="立享折扣" v-if="form.type==2">
                        <el-input v-model="form.discount" type="number" placeholder="请输入折扣，如九折，请输入数字9"/>
                    </el-form-item>

                    <el-form-item label="指定商品参与">
                        <el-select v-model="form.pro" multiple clearable placeholder="如指定商品享受首单优惠，请选择">
                            <el-option
                                    v-for="item in pro"
                                    :key="item.id"
                                    :label="'【ID:'+item.id+'】'+item.title"
                                    :value="item.id"
                                />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="仅首单中单价最低的商品享受折扣" v-if="form.type == 2">
                        <el-switch v-model="form.first_pro"></el-switch>
                    </el-form-item>

                    <el-form-item label="">
                         <el-button type="primary" style="margin-left: 0px" @click="subform">保 存</el-button>
                    </el-form-item>

                    </el-form>
            </div>
        </el-card>
    </div>
</template>

<script setup lang="ts">
import { onMounted, provide, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import createAxios from "/@/utils/axios";
import {ElMessage, ElMessageBox} from "element-plus";
import {
    Setting
} from '@element-plus/icons-vue'

defineOptions({
    name: 'mk/firstorder',
})
const load = ref(false)
const { t } = useI18n()
const shareset = () => {
        baTable.form.operate = 'Setting'  //显示组件弹窗
        baTable.form.loading = false
}
const form = ref({})
const pro = ref([])
const subform = () => {
    return createAxios({
        url: '/admin/mk.Firstorder/setting',
        method: 'post',
        data:{'data':form.value,'act':'post'}
    }).then(res => {
        if(res.data.code == 1){
            ElMessage({'message':'保存成功','type':'success'})
        }else{
            ElMessage({'message':res.data.msg,'type':'error'}) 
        }  
    })
}
const getpro = () =>{
    load.value = true
    return createAxios({
        url: '/admin/goods.Goods/lists',
        method: 'get',
        params:{}
    }).then(res => {
            pro.value = res.data.list
            getsettings()
    })
}
const getsettings = () =>{
    return createAxios({
        url: '/admin/mk.Firstorder/setting',
        method: 'post',
        data:{'act':'getdata'}
    }).then(res => {
            form.value = res.data.data
            load.value = false
    })
}
onMounted(() => {
        getpro()
       
})
</script>

<style scoped lang="scss"></style>